package com.example.mapp.buildSql;

import com.example.ext.entity.ExtDailyInspection;
import org.apache.ibatis.jdbc.SQL;

/**
 * Created by simon on 2017/10/20.
 */
public class DailyInspectionMappSql {

    public String queryList(ExtDailyInspection extDailyInspection){
        String select = " a.*, b.user_name as checkUserName";
        String table =" daily_inspection a left join sys_user b on a.check_user_id=b.id";
        String whereParam="";
        if(extDailyInspection.getElevatorId()!=null && extDailyInspection.getElevatorId()>0){
            whereParam+=" and a.elevator_id = #{elevatorId}";
        }
        if(extDailyInspection.getIsUnusual()!=null && !extDailyInspection.getIsUnusual().equals("")){
            whereParam+=" and a.is_unusual = #{isUnusual}";
        }
//        else{
//            whereParam+=" and (a.is_unusual = '0' or a.is_unusual = '1')";
//        }
        String where = " 1=1 "+whereParam;
        return new SQL(){{
            SELECT(select);
            FROM(table);
            WHERE(where);
            ORDER_BY("id desc");
        }
        }.toString();
    }
}
